package com.projectbox.web;

import java.io.IOException;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.projectbox.model.Rule;
import com.projectbox.service.UserService;
import com.projectbox.utility.RuleUtility;

@Controller
@RequestMapping("/rule")
public class RuleController {
	private UserService userService;
	private RuleUtility ruleUtility;
	
	public void setRuleUtility(RuleUtility ruleUtility) {
		this.ruleUtility = ruleUtility;
	}
	
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	@RequestMapping(method = RequestMethod.GET)
    public String displayRules(Model model) {
		model.addAttribute("user", userService.getCurrentUser());
		String content = null;
		try {
			content= ruleUtility.getRule();
		} catch (IOException e) {
		}
		
		Rule rule = new Rule();
		rule.setContent(content);
		
		model.addAttribute("rule", rule);
		return "rule";
	}
}
